<?php
include_once("functions/db_manipulate.php");

if (!init()) {
  redirect("?action=login");
} else if (!isConversationMember()) {
  exit();
}

checkIfDialogRead($_GET['did']);


$messagesResultSet = getConversation($_GET['did']);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type"
        content="text/html; charset=<?= getMessageByKey("default.charset") ?>"/>
  <title><?= getMessageByKey("conversation.title") ?></title>
  <link rel="stylesheet" href="css/navigation.css">
  <link rel="stylesheet" type="text/css" href="css/menu.css">
  <link rel="stylesheet" type="text/css" href="css/common.css">
  <link rel="stylesheet" type="text/css" href="css/messages.css">
  <script src="resources/jquery.js"></script>

<body>
<?php
include_once("menu.php");
?>

<div class="maincommon">

  <div class="dialogheader">
    <?= getMessageByKey("conv.user.header") ?> '<? getDialogPartner($_GET['did']) ?>':
  </div>

  <?php
  while ($message = mysql_fetch_assoc($messagesResultSet)) {

    if ($message['uid'] == $_SESSION['id']) {
      $style = "";
    } else {
      $style = "style='margin-left: 58%; text-align: right'";
    }

    ?>

    <div class="messagediv">
      <div class="header">
        <div class="author" <?= $style ?>>
          <?= $message['author'] ?> (<?= $message['date'] ?> <?= $message['time'] ?>):
        </div>
      </div>
      <div class="content">
        <?= processText($message['content']) ?>
      </div>
      <?
      if ($message['uid'] == $_SESSION['id']) {
        ?>
        <div class="buttonsdiv" onclick="$('#deletediv<?= $message['id'] ?>').slideDown('slow')">
          <div class="button">
            <?= getMessageByKey("button.general.delete") ?>
          </div>
        </div>
        <div class="deletediv" id="deletediv<?= $message['id'] ?>">
          <?= getMessageByKey("conv.msg.drop.ask") ?>
          <div class="buttonsdiv">
            <div class="button" onclick="location.href='?action=mesdelhan&mid=<?= $message['id'] ?>'">
              <?= getMessageByKey("general.yes") ?>
            </div>
            <div class="button" onclick="$('#deletediv<?= $message['id'] ?>').slideUp('slow')">
              <?= getMessageByKey("button.general.cancel") ?>
            </div>
          </div>
        </div>
      <?
      }
      ?>

    </div>
  <?php
  }
  ?>

  <a name="lmsg"></a>

  <form action="?action=addmes" method="post" id="addform">

    <div class="newcomment">
      <div class="info">
        <?= getMessageByKey("conv.msg.new") ?>
      </div>
      <textarea name="content" rows="11"
                placeholder="<?= getMessageByKey("conv.msg.new.placeholder") ?>"></textarea>

      <div class="buttonsdiv">

        <div class="button" onclick="$('#addform').submit()">
          <?= getMessageByKey("button.general.send") ?>
        </div>
      </div>
    </div>
    <input type="hidden" name="did" value="<?= $_GET['did'] ?>">
  </form>

</div>

    <?php
    include_once("navigation.php");
    ?>
</body>
</html>

</head>

